Provides a callback interface for DomainObjects to convert a database type to a field type when retrieving a value from the database and vice versa when storing a field to the database. Implement this interface when a persistable object field type is different from the database column type.
For a list of all members of this type, see FieldConversion<FieldConversionSubClass> Members.
System.Object
FieldConversion<FieldConversionSubClass>
author: Richard Beauchamp
$Id: FieldConversion.cs 156 2006-06-22 14:19:47Z rbeauchamp $
The following code sample demonstrates an implementation of IFieldConversion that converts between value of Int32.MinValue in a persistable object and a value of null in a database.
public class NullableIntegerConversion : IFieldConversion
{
// This method is called by DomainObjects when retrieving the column from the database.
public object DbTypeToFieldType(Type targetFieldType, object source)
{
// if the value in the database was null then return Int32.MinValue
if (source == null)
{
return Int32.MinValue;
}
else // just return the Int32 value
{
return source;
}
}
// This method is called by DomainObjects when storing a field to the database.
public object FieldTypeToDbType(DbType targetDbType, object source)
{
// if the value in the persistable object was Int32.MinValue then return null
if ((int)source == Int32.MinValue)
{
return null;
}
else // just return the Int32 value
{
return source;
}
}
}
}
For DomainObjects to use this IFieldConversion implementation at runtime, set the value of the the FieldDescriptor's ConversionClassName attribute to the name of the implementation class:
<FieldDescriptor Id="TABLE3"
FieldName="_myNullableInt"
ColumnName="NULLABLE_INT"
DbType="INTEGER"
ConversionClassName="MyNamespace.NullableIntegerConversion"
/>
Namespace: DomainObjects.Facade.Domain
Assembly: DomainObjects.Core (in DomainObjects.Core.dll)
FieldConversion<FieldConversionSubClass> Members | DomainObjects.Facade.Domain Namespace